<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript" src="${path }/static/js/product/goodsSpec.js"></script>
<div class="panel-body">
	  <input type="hidden" name="haveSpec" id="haveSpec" value="${ empty goods.haveSpec ? 0 : goods.haveSpec}" />
     <%-- other table content here --%>
     <div id="no-spec-input">
	    <!-- form filed -->
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right">成本价:</label>
			<div class="col-xs-4">
				<input type="text" id="cost" name="cost" value="${goods.cost}"
					   placeholder="成本价" class="form-control  ">
			</div>
		</div>
	     <!-- form filed -->
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right">销售价格:</label>
			<div class="col-xs-4">
				<input type="text" id="price" name="price" value="${goods.price}"
					   placeholder="销售价格" class="form-control  ">
			</div>
		</div>
		<!-- form filed -->
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right">重量:</label>
			<div class="col-xs-4">
				<input type="text" id="weight" name="weight" value="${goods.weight}"
					   placeholder="重量" class="form-control  ">
			</div>
		</div>
		<c:if test="${not empty goodsCat and param.type ne 'view'}">
		<c:if test="${goodsCat.goodsType.joinSpec eq 1 }">
		<div class="form-group">
			<label class="col-sm-2 control-label no-padding-right">规格:</label>
			<div class="col-xs-4">
				<button class="btn" id="specOpenBtn" type="button">开启规格</button>
			</div>
		</div>
		</c:if>
		</c:if>		
	</div>
	
	<div id="spec-input" style="display: none; text-align: left;">
		<c:if test="${param.type ne 'view'}">
		<button type="button" id="specCloseBtn" goodsid="${goods.id }" class="btn">关闭规格</button>
		</c:if>
		<c:forEach items="${goodsCat.goodsType.typeSpecMap }" var="specMap">
			<div class="form-group">
				<label  for="name" class="col-sm-1 control-label no-padding-right">${specMap.specification.specName }:</label>
				<div class="col-sm-11" specname="${specMap.specification.specName }">
					<c:forEach items="${specMap.specification.specValuesList }" var="specVal">
					<label class="checkbox-inline">
						<input type="checkbox" class="chk" value="${specVal.id }" spec_value="${specVal.specValue }" specid="${specMap.specification.id }">
						<c:if test="${specMap.specification.specType eq 1 }">
						<c:if test="${!empty specVal.specImage }">
						<c:choose>
						<c:when test="${fn:startsWith(specVal.specImage , 'http')}">
							<img height="20" width="20" alt="${specVal.specValue }" src="${specVal.specImage }" class="">
						</c:when>
						<c:otherwise>
							<img height="20" width="20" alt="${specVal.specValue }" src="${ctx }${specVal.specImage }" class="">
						</c:otherwise>
						</c:choose>
						</c:if>
						</c:if>
						${specVal.specValue }
					</label>
					</c:forEach>
				</div>
			</div>
		</c:forEach>
		
		<div class="detail" style="display: none;">
			<table class="spec_table table table-striped table-bordered table-hover">
				<thead>
					<tr>
						<c:forEach items="${goods.productList }" var="product" varStatus="status">
						<c:if test="${status.index == 0 }">
						<c:forEach items="${product.goodsSpecMap }" var="map">
						<th class="w1">${map.specification.specName }</th>
						</c:forEach>
						</c:if>
						</c:forEach>
						<th class="w2">货号*</th>
						<th class="w2">销售价*</th>
						<th class="w3">重量</th>
						<th class="w3">成本价</th>
						<th class="w1">操作</th>
					</tr>
				</thead>
				<tbody>
				<c:forEach items="${goods.productList }" var="product" varStatus="status">
				<c:set var="specids" value=""/>
				<c:set var="specvids" value=""/>
				<c:set var="propid" value=""/>
				<tr>
					<c:forEach items="${product.goodsSpecMap }" var="map" varStatus="statu">
					<c:if test="${statu.index > 0 }">
						<c:set var="specids" value="${specids },"/>
						<c:set var="specvids" value="${specvids },"/>
						<c:set var="propid" value="${propid }_"/>
					</c:if>
						<c:set var="specids" value="${specids}${map.specification.id }"/>
						<c:set var="specvids" value="${specvids}${map.specValues.id }"/>
						<c:set var="propid" value="${propid}${map.specValues.id }"/>
					<td>
						${map.specValues.specValue }
						<input type="hidden" name="specvalue_${status.index }" value="${map.specValues.specValue }">
						<input type="hidden" name="goods_spec_ids" value="${map.id }">
					</td>
					</c:forEach>
					<td>
						<input type="text" style="width: 150px" class="ipt form-control" name="sns" prop="sn" propid="${propid}" value="${product.sn }" autocomplete="off"> 
						<input type="hidden" name="productids" value="${product.id }" class="ipt form-control" prop="productid" propid="${propid}">
					</td>
					<td>
						<input type="hidden" value="${specids}" name="specids">
						<input type="hidden" value="${specvids}" name="specvids">
						<!-- 形成price id，用js通过此id反向选择checkobx --> 
						<input type="text" size="8" name="prices" class="ipt price form-control" value="${product.price }" prop="price" propid="${propid}" autocomplete="off">						
					</td>
					<td>
						<input type="text" size="10" name="weights" value="${product.weight }" autocomplete="off" class="ipt form-control" prop="weight" propid="${propid}" style="width: 80px">
					</td>
					<td>
						<input type="text" size="8" name="costs" value="${product.cost }" autocomplete="off" class="ipt form-control" prop="cost" propid="${propid}" style="width: 80px">
					</td>
					<td>
						<c:if test="${param.type ne 'view'}">
						<a href="javascript:;" class="delete" productid="${product.id }"><span class="glyphicon glyphicon-trash"></span></a>
						</c:if>
					</td>
				</tr>
				</c:forEach>
				</tbody>
			</table>
		</div>
	</div>
</div>